home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Tools 1
/
Amiga Tools.iso
/
egs-tools
/
egs_demo-version
/
egs_devels
/
examples
/
egs_menu
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-06
|
3KB
|
163 lines
/*
** Author: Markus van Kempen
** Date : 17. Dezember 1992
**
** This demo shows the easy way to create
** EGS menus. See InitMenu.c for the menu definition.
** The other routines are for OpenLibs, event
** and error handling.
**
** In these files you will find some useful routines
** for Open / Close libraries and error handling.
**
** (c) by VIONA-Development
**
*/
#include "includes.c"
#include "Global.h"
#include "Eventloop.c"
#include "InitMenu.c"
BOOL InitLibraries(struct OpenStructTyp *);
void CloseLibraries(struct OpenStructTyp *);
/*
** Opens the libs defined by a structure with OpenStruct type
** (see global.h)
**
*/
BOOL
InitLibraries(struct OpenStructTyp *OS)
{
struct OpenStructTyp *p = &OS[0];
while (p->Ort != NULL)
{
if ((*(p->Ort) = (ULONG) OpenLibrary(p->Name, p->Version)) == NULL)
{
printf(" Can't open %s version %d", p->Name, p->Version);
return FALSE;
}
else
{
p++;
}
}
return TRUE;
}
/*
** Close the libs
**
*/
void
CloseLibraries(struct OpenStructTyp *OS)
{
struct OpenStructTyp *p = &OS[0];
while (*(p->Ort) != NULL && p->Name != NULL)
{
CloseLibrary((void *) (*(p->Ort)));
*(p->Ort) = NULL;
p++;
}
}
/*
** This routine is for error handling.
** It closes all open things of the
** program.
**
*/
void
myError(char *string)
{
if (string != NULL)
{
if (EGSRequestBase == NULL)
{
printf("%s\n", string);
}
else
{
ErrorReq = (ER_SimpleRequestPtr) ER_CreateSimpleRequest(NULL,
(char *) string, (char *) "OK");
/*
** Open requester in the middle of the screen,
**
** if you can!
*/
ErrorReq->Req.Nw->Flags |= EI_WINDOWCENTER;
ER_DoRequest(&(ErrorReq->Req));
}
}
if (Window)
{
ErrorReq = ER_CreateSimpleRequest(NULL,
"Hello world !|This is a Requester !", "OK");
ErrorReq->Req.Nw->Flags |= EI_WINDOWCENTER;
ER_DoRequest(&(ErrorReq->Req));
}
if (FontforMenu)
EG_CloseFont(FontforMenu);
if (Window)
EI_CloseWindow(Window);
if (Menu)
EI_FreeMenu(Menu);
if (ErrorReq)
ER_DeleteRequest(&(ErrorReq->Req));
CloseLibraries(OpenStruct);
exit(0);
}
int
main(int argc, char *argv[])
{
if (argc == 2 && strcmp("?", argv[1]) == 0)
{
printf("Aufruf: %s\n Markus van Kempen 12 Nov 1992", argv[0]);
}
else
{
if (InitLibraries(OpenStruct) == FALSE)
myError("Can't OpenLibrary");
FontforMenu = (EG_EFontPtr) EG_OpenFont((struct TextAttr *) & FontStr);
if (FontforMenu == NULL)
myError("Could not open font");
Menu = InitMenu(FontforMenu);
if (Menu == NULL)
myError("Could not build menu");
newwin.Menu = Menu;
newwin.Title = argv[0];
Window = (EI_WindowPtr) EI_OpenWindow((struct EI_NewWindow *) & newwin);
if (Window)
{
HandleEvents(Window);
}
else
{
myError("Could not open window");
}
}
myError(NULL);
}